package com.xyh;

import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import rx.Observable;
import rx.Observer;


public class CommandRunMain {
  public static void main(String[] args) throws  Exception{
         RunCommand cl=new RunCommand("observe method");
         cl.observe();
         RunCommand c2=new RunCommand("toObervable method");
         Observable ob=c2.toObservable();
         ob.subscribe(new Observer<String>() {
             public void onCompleted() {
                 System.out.println("command completed");
             }

             public void onError(Throwable throwable) {

             }

             public void onNext(String o) {
                System.out.println(o);
             }
         });
         c2.toObservable();
         Thread.sleep(1000);
  }
  static class RunCommand extends HystrixCommand<String> {
       String msg;
      public RunCommand(String msg) {
          super(HystrixCommandGroupKey.Factory.asKey("TestGroup"));
          this.msg = msg;
      }
      @Override
      protected String run() throws Exception {
          System.out.println(this.msg+"111");
          return "success";
      }
  }
}
